<?php

namespace App\Http\Controllers\View;

use App\Http\Controllers\Controller;
use App\Models\User;
use Illuminate\Support\Facades\Auth;
use function redirect;

class FansController extends Controller
{

    public function __construct()
    {
        $this->middleware('auth');
    }

    //关注用户
    public function fanUser(User $user)
    {
        $this->authorize('fans',$user);
        if (!Auth::user()->isFaning($user)) {
            Auth::user()->fan($user->id);
        }

        return redirect()->back();
    }

    //取消关注
    public function unfanUser(User $user)
    {
        $this->authorize('fans',$user);
        if (Auth::user()->isFaning($user)) {
            Auth::user()->unfan($user->id);
        }
        return redirect()->back();
    }
}
